package com.zbs.framework.common.utils.email;

import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.zbs.framework.common.utils.ErrorAssert;
import org.springframework.stereotype.Component;

@Component
public class EmailUtils {

    /**
     * 群体发送简单文本邮件
     * @param mailInfo
     */
    public static void sendEMail(MailInfo mailInfo) {
        MailAccount account = new MailAccount();
        account.setHost(MailConfig.host);
        account.setPort(MailConfig.port);
        account.setAuth(true);
        account.setFrom(MailConfig.from);
        account.setUser(MailConfig.username);//这里名字需要是发送账户名字
        account.setPass(MailConfig.password); //密码，授权码
        account.setSslEnable(MailConfig.sslEnable);
        try {
            MailUtil.send(account,mailInfo.getMails(), mailInfo.getTitle(), mailInfo.getMessage(), false);
        } catch (Exception e) {
            e.printStackTrace();
            ErrorAssert.error("发送失败，请检查邮箱配置");
        }
    }
}
